package com.lifeonwalden.fincalc.utils.date;

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.List;
import java.util.function.BiFunction;

public interface InnerDateSeriesFunction {
    /**
     * @param dataList
     * @param data
     * @param startDate          include
     * @param endDate            exclude
     * @param cloneAndSetDate
     * @param <T>
     */
    static <T> void fillToNaturalSeries(List<T> dataList, T data, Instant startDate, Date endDate, BiFunction<T, Date, T> cloneAndSetDate) {
        Instant date = startDate;
        long endDateMillis = endDate.getTime();

        while (date.toEpochMilli() < endDateMillis) {
            dataList.add(cloneAndSetDate.apply(data, Date.from(date)));
            date = date.plus(1, ChronoUnit.DAYS);
        }
    }
}